import util from '../../util/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {},
    src: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function({
    id,
    c
  }) {
    //没值为扫码上车
    if (!c) {
      util.ajax("order", {
        data: {
          action:"boarding",
          id
        }
      }).then(({code,msg})=>{
        if(code == 1){
          util.tip(msg,"success",3000)
        }else{
          wx.showModal({
            title: '提示',
            content: msg,
            showCancel:false,
            confirmText:"知道了",
          })
        }
      })

    }

    wx.showLoading({
      title: '操作中...',
    })

    util.ajax("route", {
      data: {
        action: 'detail',
        id
      }
    }).then(({
      code,
      data,
      msg
    }) => {
      wx.hideLoading()
      if (code == 1) {
        this.setData({
          detail: data,
          src: `cloud://main-y1rj3.6d61-main-y1rj3-1302196139/car/${data.plateNumber}.jpg`
        })
        wx.setNavigationBarTitle({
          title: data.number,
        })
      } else {
        util.tip(msg);
      }
    }, wx.hideLoading)
    const {
      role
    } = wx.getStorageSync("user");
    if (role == 1) {
      this.setData({
        isHiddenRecord: true,
      })
    }
  },
  call() {
    wx.makePhoneCall({
      phoneNumber: this.data.detail.driverPhone,
    })
  },
  book() {
    const {
      // type,
      _id,
      // stations
    } = this.data.detail;
    // this.selectComponent('#appointment').show(_id, type, stations);
    wx.navigateTo({
      url: '/pages/appointment/appointment?id=' + _id,
    })
  },
  toRecord() {
    const {
      _id,
      number
    } = this.data.detail;
    wx.navigateTo({
      url: 'record/record?id=' + _id + '&number=' + number,
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  imageError() {
    this.setData({
      src: `../../images/bus.jpg`
    })
  }
})